<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("dinocap2", $con);
$dateTime = date("Y-m-d",strtotime("-1 day"));


error_reporting(E_ALL ^ E_NOTICE);
 //FUNCTION: Connect to PostgreSql database
 
 //create a connection to postgresql database
set_time_limit(0);
ini_set("memory_limit", "200M");
  pg_connect("host=localhost dbname=comds  user=root  password=root")
   or die('Could not connect:'.pg_last_error());

  // $select_query = pg_query("select max(id) from comds  where date = '2012-04-03' group by deviceid");
   //$select = pg_num_rows($select_query);
   $dateTime = date("Y-m-d",strtotime("-1 day"));
    pg_query("delete from comds  a  where date ='$dateTime' and a.id not in (select max(id) from comds b where date ='$dateTime' group by deviceid)");
  // $del = pg_num_rows($del_query);

//mysql_query("DELETE FROM dinocap2hd WHERE whatday < '2012-03-15' or whatday >'$dateTime'");

mysql_close($con);
?>